package one;

import java.util.Arrays;
import java.util.Scanner;
public class subarray {
	public static void main(String args[]) {
		System.out.println("请输入数组长度为：");
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();//定义数组长度
		int arr[] = new int[n];
		System.out.println("请输入数组：");
		for(int i=0;i<n;i++) {
			arr[i]=sc.nextInt();
		}
		System.out.println("您输入的数组为："+Arrays.toString(arr));
		int summax=0;
		for(int i=0;i<n;i++) {
			int sum=0;
			for(int j=i;j<n;j++) {
				sum=sum+arr[j];
				if(sum>summax) {
					summax=sum;
				}
			}
		}
		System.out.println("数组中子数组之和的最大值为："+ summax);
	}
}

